<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
  <meta name="baidu-site-verification" content="code-UjJKh3jtOo">
  <link rel="stylesheet" href="//unpkg.com/@highlightjs/cdn-assets@11.5.0/styles/atom-one-dark.min.css">
  <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
  <title>Tit1e</title>
  <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-2767111597631391" crossorigin="anonymous"></script>
  
<link rel="stylesheet" href="/css/style.css">

<meta name="generator" content="Hexo 6.3.0"><link rel="alternate" href="/atom.xml" title="Tit1e" type="application/atom+xml">
</head>

<body class="dark">
    <div class="container">
    <header class="header">
  <div class="title">
      <a href="/" class="logo">Tit1e</a>
      <div class="btn-dark"></div>
      <script>
        let bodyClx = document.body.classList;
        let btnDark = document.querySelector('.btn-dark');
        let sysDark = window.matchMedia('(prefers-color-scheme: dark)');
        let darkVal = localStorage.getItem('dark');

        let setDark = (isDark) => {
        bodyClx[isDark ? 'add' : 'remove']('dark');
        localStorage.setItem('dark', isDark ? 'yes' : 'no');
        };

        setDark(darkVal ? darkVal === 'yes' : sysDark.matches);
        requestAnimationFrame(() => bodyClx.remove('not-ready'));

        btnDark.addEventListener('click', () => setDark(!bodyClx.contains('dark')));
        sysDark.addEventListener('change', (event) => setDark(event.matches));
      </script>
  </div>
    <ul class="menu">
        
        
        
        
        <li class="menu-item ">
            <a href="/" class="menu-item-link">Home</a>
        </li>
        
        
        <li class="menu-item ">
            <a href="/archives/" class="menu-item-link">Archives</a>
        </li>
        
        
        <li class="menu-item ">
            <a href="/atom.xml" class="menu-item-link">RSS</a>
        </li>
        
        
        <li class="menu-item ">
            <a target="_blank" rel="noopener" href="https://pixeltimer.art" class="menu-item-link">Pixel Timer</a>
        </li>
        
    </ul>
    <div class="search-box">
        <input type="search" id="search" placeholder="搜索">
    </div>
</header>
    <article class="post">
  <div class="post-meta">
    <span class="post-time">7 / 22, 2018</span>
  </div>
  <div class="post-title">
    <h1 class="title">MAMP 配置虚拟主机</h1>
  </div>
  
  <ul class="post-tags">
    
    <li class="tag-item">
      #学习
    </li>
    
    <li class="tag-item">
      #mac
    </li>
    
  </ul>
  
  <div class="post-content">
    <p>公司由于项目调整，在跑本地项目的时候需要指定域名，当然可以通过配置修改这个指定的域名，但是借此机会折腾一下也好。教程网上有很多，我重新整理一下一是加深记忆，二是日后如有需要方便查找，于是有了这篇文章。参考的文章链接在文末。</p>
<p>MAMP 我用的是免费版的，MAMP Pro 好像可以直接在界面设置，但是免费版也是可以实现的，只是设置过程没那么简单明了，但也不是非常难。</p>
<span id="more"></span>
<p>第一步：打开 <code>/Applications/MAMP/conf/apache/httpd.conf</code></p>
<p>第二步：搜索 <code>httpd-vhosts</code>，定位至 <code>#Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf</code>，删除前面的 <code>#</code>，保存。</p>
<p>第三步：打开 <code>/Applications/MAMP/conf/apache/extra/httpd-vhosts.conf</code>。这个文件中你可以看到被 <code>&lt;VirtualHost *:80&gt;&lt;/VirtualHost&gt;</code> 标签包裹的代码，我的是这样的，可能略微有些不同，但没关系。</p>
<pre><code>&lt;VirtualHost *:80&gt;
    ServerAdmin webmaster@dummy-host2.example.com
    DocumentRoot &quot;/Users/xxxx/Public/Program/dmp&quot;
    ServerName localhost
    ServerAlias localhost
    ErrorLog &quot;logs/dummy-host2.example.com-error_log&quot;
    CustomLog &quot;logs/dummy-host2.example.com-access_log&quot; common
&lt;/VirtualHost&gt;
</code></pre>
<p>这就是我们需要修改的配置。默认应该有个 localhost 的配置（有点忘了）。</p>
<p>第四步：修改 <code>DocumentRoot</code> 为这是项目目录，修改 <code>ServerName</code> 为你想设定的域名，<code>ServerAlias</code> 可以为域名设定别别名，可以不设置。保存文件。</p>
<p>到此 MAMP 的配置结束了，我们还需要配置 hosts 文件，将 127.0.0.1 指向我们设定的域名，不然用域名还是无法访问到。<br>Mac 上推荐使用 <a target="_blank" rel="noopener" href="https://itunes.apple.com/cn/app/ihosts-%E7%BC%96%E8%BE%91%E7%A5%9E%E5%99%A8/id1102004240?mt=12">iHosts</a> 来设置 hosts，很实用的一个小工具，免费版的足够日常使用了。当然你也可以用其他方式，具体也可以搜索引擎搜索，网上教程一大堆。</p>
<p>在 hosts 文件中加入 <code>127.0.0.1  配置的域名</code>，保存。重启服务器，重连一下网络即可。</p>
<p>用 shadowsocks 的小伙伴要注意，要把代理模式设为 PAC自动模式，全局模式会导致域名无法访问，这个问题当初找了好久才发现。</p>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/it_r00t/article/details/75254933">参考地址</a></p>

  </div>
  <div class="post-near">
    
    <a
      class="post-near-prev"
      href="/p/bdaa78ac.html"
      title="jsTree 不同节点不同右键菜单"
    >
      <span class="arrow">←</span>
      <span class="post-near-title">
        jsTree 不同节点不同右键菜单
      </span>
    </a>
    
    
    <a
      class="post-near-next"
      href="/p/895794e6.html"
      title="webpack 通过 NODE_ENV 判断当前环境"
    >
      <span class="post-near-title">
        webpack 通过 NODE_ENV 判断当前环境
      </span>
      <span class="arrow">→</span>
    </a>
    
  </div>
</article>

    <footer class="footer">
  <p>本博客采用 <a class="license-link" rel="license noopener" target="_blank" href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh">署名-非商业性使用-相同方式共享 4.0 国际</a>协议进行许可</p>
  <p>
    <span>Thanks For <a target="_blank" rel="noopener" href="https://github.com/nanxiaobei/hugo-paper" taget="_blank">hugo-paper</a></span>
    <span style="margin-left: 10px;">&copy; 2016-2025 by Tit1e</span>
  </p>
</footer>
    </div>
    <script src="//unpkg.com/@highlightjs/cdn-assets@11.5.0/highlight.min.js"></script>
<script>
  hljs.initHighlightingOnLoad();
  var _hmt = _hmt || [];
    (function() {
    var hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?6349d3bc54baea0b04a65145c5e3b799";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
    })();
    const block = document.querySelectorAll('.post-content')[0]
    block.addEventListener('click', e => {
        const {nodeName, src} = e.target
        if(nodeName !== 'IMG') return
        document.body.classList.add('overflow-hidden')
        const div = document.createElement('div')
        div.id = 'global-cover'
        div.title = '点击关闭'
        const a = document.createElement('a')
        a.href = src
        a.target="_blank"
        a.title = '点击打开原图'
        const img = document.createElement('img')
        img.className = 'show-pic'
        img.src = src
        a.appendChild(img)
        div.appendChild(a)
        document.body.appendChild(div)
    })
    document.body.addEventListener('click', e => {
        if(e.target.id === 'global-cover'){
            document.body.classList.remove('overflow-hidden')
            document.body.removeChild(e.target)
        }
    })
</script>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-7M04VN3JZ4"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-7M04VN3JZ4');
</script>

<script src="/js/search.js"></script>


</body>
</html>